package love.bot.forli.group.review.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import love.bot.forli.group.review.bean.Dto.GroupListDto;
import love.bot.forli.group.review.bean.Result;
import love.bot.forli.group.review.bean.Vo.AddGroupVo;
import love.bot.forli.group.review.entity.QuestionGroup;
import love.bot.forli.group.review.service.QuestionGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Kontori
 */
@Api(tags = "题组相关接口")
@RestController
@RequestMapping("/questionGroup")
@Transactional(rollbackFor = {Throwable.class})
public class QuestionGroupController {

    private QuestionGroupService questionGroupService;

    @Autowired
    public void setQuestionGroupService(QuestionGroupService questionGroupService) {
        this.questionGroupService = questionGroupService;
    }

    @ApiOperation("获取所有题组")
    @GetMapping("/list")
    public Result<List<GroupListDto>> groupList() {
        return questionGroupService.groupList();
    }

    @ApiOperation("修改题组")
    @PostMapping("/edit")
    public Result<Object> editQuestionGroup(@RequestBody QuestionGroup questionGroup) {
        return questionGroupService.updateById(questionGroup) ?
                Result.success("修改成功", null) : Result.fail("修改失败");
    }

    @ApiOperation("删除题组")
    @DeleteMapping("/delete/{groupId}")
    public Result<Object> deleteGroup(@PathVariable("groupId") Integer groupId) {
        return questionGroupService.deleteGroup(groupId);
    }

    @ApiOperation("新增题组")
    @PostMapping("/add")
    public Result<Object> addGroup(@RequestBody AddGroupVo addGroupVo) {
        return questionGroupService.addGroup(addGroupVo);
    }

}
